var gulp = require("gulp"),
	connect = require("gulp-connect");
	sass = require("gulp-sass"),
	dgbl = require("del-gulpsass-blank-lines"),
	rename = require("gulp-rename");

gulp.task('connect',function(done){ //创建本地服务器
	connect.server({
		root: 'src',
		port: 4200,
		livereload: true //自动刷新
	})
	done();
})


//添加页面html文件更改刷新
function HtmlTask(){
	return gulp.src('src/**.html')
	.pipe(connect.reload());
}

function SassTask(){
	return gulp.src('src/scss/style.scss') 
	.pipe(sass({outputStyle: 'compact'}))//编译scss
	.pipe(dgbl())// 将样式合并成一行
	//.pipe(rename({extname: ".wxss"}))  //开发小程序可修改扩展名
	.pipe(gulp.dest('src/css/')) //导出css
	.pipe(connect.reload()); //执行刷新浏览器
}

function WatchTask(done) {
	gulp.watch(['src/scss/style.scss'], gulp.series(SassTask));
	gulp.watch(['./src/*.html'], gulp.series(HtmlTask));
	done();
}


gulp.task('default',gulp.series(['connect',WatchTask])); //执行任务组